#include "ProCon2.hpp"
#include "fun.hpp"

void *Pro(void *asg)
{
    pthread_detach(pthread_self());
    PC<computer> *qc = (PC<computer> *)asg;
    char *por = "+-*/";
    while (true)
    {
        sleep(1);
        int x = rand() % 100 + 1;
        int y = rand() % 50;
        int p = rand() % 4;
        computer su(x, y, por[p]);
        qc->Push(su);
    }
}
void *Con(void *asg)
{
    pthread_detach(pthread_self());
    PC<computer> *qc = (PC<computer> *)asg;
    while (true)
    {
        sleep(1);
        computer su;
        qc->Pop(su);
        int data = su.fun();
        std::cout << su.x << su.por << su.y << "=" << data << std::endl;
    }
}
int main()
{
    pthread_t producer, consumer;
    srand((unsigned long)time(nullptr));
    PC<computer> *qc = new PC<computer>();
    pthread_create(&producer, nullptr, Pro, qc);
    pthread_create(&consumer, nullptr, Con, qc);

    while (true)
        ;
    return 0;
}